/**
 * 
 */
package com.rs.controller;

import java.awt.EventQueue;

import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;

import com.rs.model.ZhGoOut;
import com.rs.model.ZhUser;
import com.rs.service.ZhGoOutService;
import com.rs.util.SpringContextUtils;

import javax.swing.JDesktopPane;
import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.SpringLayout;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.JComboBox;
import javax.swing.DefaultComboBoxModel;




/**
 * @author zjw
 *
 */
@SuppressWarnings("serial")
public class GoOutUpdate extends JFrame {

	private JPanel contentPane;
	private JTextField txt_uname;
	private JTextField txt_ktime;
	private JTextField txt_length;
	private JTextField txt_auname;
	private JTextField txt_img;
	private JTextField txt_jtime;
	private JTextField txt_reason;
	@SuppressWarnings("rawtypes")
	private final JComboBox comboBox;
	
	
	private Integer gid;
	ZhGoOutService gooutservice = SpringContextUtils.getBean(ZhGoOutService.class);
//	private JLabel lb_ktime;
//	private JLabel lb_jtime;
//	private JLabel lb_auname;
//	private JLabel lb_audit;
	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					GoOutUpdate frame = new GoOutUpdate(null,null);
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 * @param user 
	 */
	@SuppressWarnings({ "rawtypes", "unchecked" })
	public GoOutUpdate(final JDesktopPane jdesktoppane, final ZhUser user) {
		
		
		addWindowListener(new WindowAdapter() {
			@Override
			public void windowClosing(WindowEvent e) {

				GoOutList goodslist = new GoOutList(jdesktoppane,user);
				goodslist.setVisible(true);
				
				jdesktoppane.add(goodslist);
				
			}
			
		});

		setResizable(false);

		setTitle("外出审核信息");
		setBounds(100, 100, 578, 512);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		SpringLayout sl_contentPane = new SpringLayout();
		contentPane.setLayout(sl_contentPane);
		
		JLabel lb_uname = new JLabel("申请人姓名：");
		sl_contentPane.putConstraint(SpringLayout.WEST, lb_uname, 55, SpringLayout.WEST, contentPane);
		contentPane.add(lb_uname);
		
		txt_uname = new JTextField();
		sl_contentPane.putConstraint(SpringLayout.WEST, txt_uname, 13, SpringLayout.EAST, lb_uname);
		sl_contentPane.putConstraint(SpringLayout.NORTH, lb_uname, 3, SpringLayout.NORTH, txt_uname);
		sl_contentPane.putConstraint(SpringLayout.NORTH, txt_uname, 43, SpringLayout.NORTH, contentPane);
		txt_uname.setEditable(false);
		contentPane.add(txt_uname);
		txt_uname.setColumns(10);
		
		JLabel lb_img = new JLabel("外出图片地址：");
		contentPane.add(lb_img);
		
		txt_img = new JTextField();
		txt_img.setEditable(false);
		sl_contentPane.putConstraint(SpringLayout.NORTH, lb_img, 3, SpringLayout.NORTH, txt_img);
		contentPane.add(txt_img);
		txt_img.setColumns(10);
		
		JLabel lb_length = new JLabel("外出时长：");
		sl_contentPane.putConstraint(SpringLayout.NORTH, lb_length, 55, SpringLayout.SOUTH, lb_uname);
		sl_contentPane.putConstraint(SpringLayout.EAST, lb_length, 0, SpringLayout.EAST, lb_uname);
		contentPane.add(lb_length);
		
		txt_length = new JTextField();
		txt_length.setEditable(false);
		sl_contentPane.putConstraint(SpringLayout.WEST, txt_length, 0, SpringLayout.WEST, txt_uname);
		sl_contentPane.putConstraint(SpringLayout.EAST, txt_length, -304, SpringLayout.EAST, contentPane);
		sl_contentPane.putConstraint(SpringLayout.NORTH, txt_length, 49, SpringLayout.SOUTH, txt_uname);
		contentPane.add(txt_length);
		txt_length.setColumns(10);
		
		JLabel lb_reason = new JLabel("外出事由：");
		sl_contentPane.putConstraint(SpringLayout.EAST, lb_img, 0, SpringLayout.EAST, lb_reason);
		sl_contentPane.putConstraint(SpringLayout.EAST, txt_uname, -50, SpringLayout.WEST, lb_reason);
		sl_contentPane.putConstraint(SpringLayout.NORTH, lb_reason, 0, SpringLayout.NORTH, lb_uname);
		contentPane.add(lb_reason);
		
		txt_reason = new JTextField();
		txt_reason.setEditable(false);
		sl_contentPane.putConstraint(SpringLayout.EAST, lb_reason, -16, SpringLayout.WEST, txt_reason);
		sl_contentPane.putConstraint(SpringLayout.NORTH, txt_img, 49, SpringLayout.SOUTH, txt_reason);
		sl_contentPane.putConstraint(SpringLayout.WEST, txt_img, 0, SpringLayout.WEST, txt_reason);
		sl_contentPane.putConstraint(SpringLayout.EAST, txt_img, 0, SpringLayout.EAST, txt_reason);
		sl_contentPane.putConstraint(SpringLayout.NORTH, txt_reason, 43, SpringLayout.NORTH, contentPane);
		sl_contentPane.putConstraint(SpringLayout.WEST, txt_reason, 384, SpringLayout.WEST, contentPane);
		sl_contentPane.putConstraint(SpringLayout.EAST, txt_reason, -67, SpringLayout.EAST, contentPane);
		contentPane.add(txt_reason);
		txt_reason.setColumns(10);
		
		JLabel lb_ktime;
		lb_ktime = new JLabel("开始时间：");
		sl_contentPane.putConstraint(SpringLayout.EAST, lb_ktime, 0, SpringLayout.EAST, lb_uname);
		contentPane.add(lb_ktime);
		
		txt_ktime = new JTextField();
		sl_contentPane.putConstraint(SpringLayout.NORTH, txt_ktime, 37, SpringLayout.SOUTH, txt_length);
		sl_contentPane.putConstraint(SpringLayout.WEST, txt_ktime, 13, SpringLayout.EAST, lb_ktime);
		sl_contentPane.putConstraint(SpringLayout.SOUTH, lb_ktime, 0, SpringLayout.SOUTH, txt_ktime);
		txt_ktime.setEditable(false);
		contentPane.add(txt_ktime);
		txt_ktime.setColumns(10);
		
		JLabel lb_jtime;
		lb_jtime = new JLabel("结束时间：");
		sl_contentPane.putConstraint(SpringLayout.EAST, txt_ktime, -50, SpringLayout.WEST, lb_jtime);
		sl_contentPane.putConstraint(SpringLayout.NORTH, lb_jtime, 0, SpringLayout.NORTH, lb_ktime);
		sl_contentPane.putConstraint(SpringLayout.EAST, lb_jtime, 0, SpringLayout.EAST, lb_img);
		contentPane.add(lb_jtime);
		
		txt_jtime = new JTextField();
		txt_jtime.setEditable(false);
		sl_contentPane.putConstraint(SpringLayout.NORTH, txt_jtime, 39, SpringLayout.SOUTH, txt_img);
		sl_contentPane.putConstraint(SpringLayout.WEST, txt_jtime, 0, SpringLayout.WEST, txt_img);
		sl_contentPane.putConstraint(SpringLayout.EAST, txt_jtime, 0, SpringLayout.EAST, txt_img);
		contentPane.add(txt_jtime);
		txt_jtime.setColumns(10);
		
		JLabel lb_auname;
		lb_auname = new JLabel("审核人姓名：");
		sl_contentPane.putConstraint(SpringLayout.EAST, lb_auname, 0, SpringLayout.EAST, lb_uname);
		contentPane.add(lb_auname);
		
		txt_auname = new JTextField();
		txt_auname.setEditable(false);
		sl_contentPane.putConstraint(SpringLayout.NORTH, txt_auname, 49, SpringLayout.SOUTH, txt_ktime);
		sl_contentPane.putConstraint(SpringLayout.NORTH, lb_auname, 3, SpringLayout.NORTH, txt_auname);
		sl_contentPane.putConstraint(SpringLayout.WEST, txt_auname, 0, SpringLayout.WEST, txt_uname);
		sl_contentPane.putConstraint(SpringLayout.EAST, txt_auname, 0, SpringLayout.EAST, txt_uname);
		contentPane.add(txt_auname);
		txt_auname.setColumns(10);
		
		JLabel lb_audit;
		lb_audit = new JLabel("审核状态：");
		sl_contentPane.putConstraint(SpringLayout.NORTH, lb_audit, 0, SpringLayout.NORTH, lb_auname);
		sl_contentPane.putConstraint(SpringLayout.EAST, lb_audit, 0, SpringLayout.EAST, lb_img);
		contentPane.add(lb_audit);
		
		comboBox = new JComboBox();
		sl_contentPane.putConstraint(SpringLayout.EAST, comboBox, 0, SpringLayout.EAST, txt_img);
		comboBox.setModel(new DefaultComboBoxModel(new String[] {"待审核", "审核成功", "审核失败"}));
		sl_contentPane.putConstraint(SpringLayout.NORTH, comboBox, -3, SpringLayout.NORTH, lb_auname);
		sl_contentPane.putConstraint(SpringLayout.WEST, comboBox, 0, SpringLayout.WEST, txt_img);
		contentPane.add(comboBox);
		
		JButton btn_update = new JButton("修改");
		sl_contentPane.putConstraint(SpringLayout.NORTH, btn_update, 81, SpringLayout.SOUTH, txt_auname);
		sl_contentPane.putConstraint(SpringLayout.WEST, btn_update, 217, SpringLayout.WEST, contentPane);
		sl_contentPane.putConstraint(SpringLayout.EAST, btn_update, -223, SpringLayout.EAST, contentPane);
		btn_update.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				ZhGoOut goout = new ZhGoOut();
				goout.setGoAudit(comboBox.getSelectedIndex());
				goout.setGoAuid(user.getuId());
				goout.setGoId(gid);
				gooutservice.updateGoOutAudit(goout);
				JOptionPane.showMessageDialog(new JButton(), "修改成功！");
//				new GoodsList().setVisible(true);
			}
		});
		contentPane.add(btn_update);
		
//		JButton btn_reset = new JButton("重置");
//		btn_reset.addActionListener(new ActionListener() {
//			public void actionPerformed(ActionEvent e) {
////				txt_gname.setText("");
//				txt_reason.setText("");
//				txt_length.setText("");
//				txt_img.setText("");
//			}
//		});
//		sl_contentPane.putConstraint(SpringLayout.NORTH, btn_reset, 0, SpringLayout.NORTH, btn_update);
//		sl_contentPane.putConstraint(SpringLayout.WEST, btn_reset, 104, SpringLayout.EAST, btn_update);
//		sl_contentPane.putConstraint(SpringLayout.EAST, btn_reset, -116, SpringLayout.EAST, contentPane);
//		contentPane.add(btn_reset);
		
		
		
	}
	
	public void select(Object id){
	
		ZhGoOut goout = new ZhGoOut();
		goout.setGoId(Integer.parseInt(id+""));
		goout.setPageNum(1);
		ZhGoOut att = gooutservice.selectGoOutAudit(goout).getList().get(0);
		txt_ktime.setText(att.getGoKtimes());
		txt_auname.setText(att.getGoAuname());
		txt_jtime.setText(att.getGoJtimes());
		txt_img.setText(att.getGoImg());
		txt_length.setText(att.getGoLength()+"");
		txt_reason.setText(att.getGoReason());
		txt_uname.setText(att.getGoUname());
		comboBox.setSelectedIndex(att.getGoAudit());
		gid = Integer.parseInt(id+"");
	}
}
